<template>
  <a-select show-search placeholder="请选择"
   option-filter-prop="children"
    style="width: 100%" 
    :value="getValueSting"
    :filter-option="filterOption" @change="handleChange">
    <a-select-option v-for="t in ProductIdOptions" :key="t.value" :value="t.value">{{t.text}}</a-select-option>
  </a-select>
</template>

<script>
  import { httpAction,getAction } from '@/api/manage'
  import  filterObj  from '@/utils/util';
  
  export default {
    name: 'ProSelect',
    props: {
      value: {
        value: [String, Number],
        required: false
      },
      triggerChange:{
        value: Boolean,
        required: false,
        default: true
      },
      type: {
        value: Number,
        required: false,
        default: 0
      },
    },
    data() {
      return {
        ProductIdOptions: [],
      }
    },
    computed: {
      getValueSting(){
        console.log(this.value);
        return this.value != null ? this.value : undefined;
      },
    },
    mounted() {

    },
    watch: {
      value: {
        immediate: true,
        handler() {
          console.log(this.value);
          this.getProductIdOptions(this.type);
        }
      },
    },
    created() {
      
    },
    methods: {
     
      handleChange(val) {
        if(this.triggerChange){
          this.$emit('change', val);
        }else{
          this.$emit('input', val);
        }
      },
      getProductIdOptions(type) {
        let param ={type:type}
        getAction("/crm/product/getproductId",param)
          .then((res) => {
            if (res.success) {
              this.ProductIdOptions = res.result;
            } else {
              that.$message.warning(res.message)
            }
          })
      },
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
    },
    model: {
      prop: 'value',
    },
  }
</script>

<style>
</style>
